package com.jinlong.mq.distribute;

import com.alibaba.fastjson.JSONObject;
import com.jinlong.adapter.MassageAdapter;
import com.jinlong.constants.MQInterfaceType;
import com.jinlong.service.SMSMaileboxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * 消费消息，从对垒中回去消息
 */
@Slf4j
@Component
public class ConsumerDistribute {

    @Autowired
    private SMSMaileboxService smsMaileboxService;
    @JmsListener(destination = "queue://mail_queue")
    public void distribute(String json){
        log.info("###消息服务####收到消息，消息内容为json{}:",json);
        if(StringUtils.isEmpty(json)){
            return;
        }
        JSONObject jsonObject = new JSONObject().parseObject(json);
        JSONObject header = jsonObject.getJSONObject("header");
        String interfaceType = header.getString("interfaceType");
        MassageAdapter massageAdapter = null;
        switch (interfaceType){
            case MQInterfaceType.SMS_MAIL:
                massageAdapter = smsMaileboxService;
                break;
            default:
                break;
        }
        JSONObject content = jsonObject.getJSONObject("content");
        massageAdapter.distribute(content);

    }
}
